<meta title="人群管理"/>
<div class="p">
    <div class="m-b-xs">
        <div class="btn-group">
            <a href="javascript:;" class="btn btn-default btn-xs"
               s-click="add()">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>
        <a href="javascript:;" class="btn btn-default btn-xs s-loading-icon "
           s-click="return $crowdsGrid.refresh()">
            <i class="fa fa-refresh s-loading-spinner"></i>
        </a>
    </div>
    <div id="crowdsGrid"
         s='datac,nda'
         s-data="S.get('/api/crowd/list/VALID')">
        <table class="table table-striped table-bordered table-middle">
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>最早创建时间</th>
                <th>最后创建时间</th>
                <th>最早活跃时间</th>
                <th>最后活跃时间</th>
                <th>会员级别</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop">
            <tr s-loop-role="empty">
                <td colspan="9">暂无数据</td>
            </tr>
            <tr s-loop-role="row" s="datac" class="crowd">
                <td name="id"></td>
                <td name="name"></td>
                <td name="minCreateTime"></td>
                <td name="maxCreateTime"></td>
                <td name="minActiveTime"></td>
                <td name="maxActiveTime"></td>
                <td name="userLevelTitle"></td>
                <td name="statusTitle"></td>
                <td class="text-right">
                    <input autocomplete="off" type="button" class="btn btn-xs btn-danger" value="删除" s-click="del(this)"/>
                    <input autocomplete="off" type="button" class="btn btn-xs btn-info" value="编辑" s-click="edit(this)"/>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    function edit($this) {
        var data = $this.parent().data();
        S.popupOpen("/crowd/crowdEdit.html", {crowd: data}).done(function(rs) {
           rs && $crowdsGrid.refresh();
        })
    }

    function add() {
        S.popupOpen("/crowd/crowdAdd.html").done(function(rs) {
            rs && $crowdsGrid.refresh();
        })
    }

    function del($this) {
        var data = $this.parent().data();
        S.confirm("确定删除吗").done(function() {
            S.put("/api/crowd/status/" + data.id + "/DELETED").done(function() {
                $crowdsGrid.refresh();
            })
        })
    }
</script>